package com.one.consumer.user.ui;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.one.common.config.RouterPath;
import com.one.common.manager.RouterManager;
import com.one.common.view.base.IListView;
import com.one.common.view.widget.MyTitleBar;
import com.one.consumer.BaseListActivityC;
import com.one.consumer.R;
import com.one.consumer.user.model.extra.InvoiceExtra;
import com.one.consumer.user.model.item.LookUpItem;
import com.one.consumer.user.presenter.LookUpListPresenter;
import com.one.consumer.user.ui.binder.LookUpBinder;

/**
 * author ：zhulunjun
 * email  ：zhulunjun@qq.com
 * date   ：2018/10/28 3:33 PM
 * description ：发票管理页面
 **/
@Route(path = RouterPath.INVOICE_MANAGER)
public class InvoiceManagerActivity extends BaseListActivityC<LookUpListPresenter> implements IListView,LookUpBinder.LookUpListener{
    private InvoiceExtra mExtra;
    @Override
    protected void initPresenter() {
        mPresenter = new LookUpListPresenter(this, this);
    }

    @Override
    public void registerDate() {
        register(LookUpItem.class, new LookUpBinder(this));
    }

    @Override
    public void loadData() {
        mPresenter.getInvoiceList();
    }

    @Override
    protected void initTitle() {
        super.initTitle();
        mExtra = (InvoiceExtra) getIntent().getSerializableExtra(InvoiceExtra.getExtraName());
        String title = "发票管理";
        if(mExtra!=null && mExtra.getType() == InvoiceExtra.CHECK){
            title = "选择抬头";
        }
        getMyTitleBar().setMode(MyTitleBar.Mode.BACK_TITLE_RIMG)
                .setTitleText(title)
                .setRightImg(R.mipmap.ic_add_black);
    }

    @Override
    protected void onClickRightImg() {
        super.onClickRightImg();
        RouterManager.getInstance().go(RouterPath.ADD_LOOK_UP, new InvoiceExtra(InvoiceExtra.ADD));

    }

    @Override
    public boolean onEmpty() {
        return true;
    }


    @Override
    protected void onResume() {
        super.onResume();
        doRefresh();
    }

    @Override
    public void onDelete(LookUpItem item) {
        doRefresh();
    }

    @Override
    public void onLookUpClick(LookUpItem item) {
        if(mExtra!=null && mExtra.getType() == InvoiceExtra.CHECK){
            mExtra.setLookUpItem(item);
            RouterManager.getInstance().goAndFinish(this,RouterPath.ADD_INVOICE, mExtra);
        } else {
            // 编辑
            RouterManager.getInstance().go(RouterPath.ADD_LOOK_UP,
                    new InvoiceExtra(InvoiceExtra.UPDATE, item));
        }
    }
}
